#!/bin/bash

r_host=$1
r_login=$2
r_folder=$3

path="/data/samba_share/imei/out/"
tmpfile="result_list"

print_usage()
{
   echo "Usage: $0 <remote host> <login> <remote folder>"
   echo "Upload the given result file on the given remote directory "
   echo "on the given remote host by using SSH protocol."
}

if [ "x$r_folder" == "x" ]; then
   echo "[ERROR] All arguments not available."
   print_usage
   exit 1
fi

# looking up result files to upload to the remote server
find $path -name "result_f*" > $tmpfile

C=`cat $tmpfile | wc -l`
if [ $C -eq 0 ]; then
    echo "`date +'%Y/%m/%d %H:%M:%S'` BASH SCRIPT: No file to upload."
    exit
fi

for i in `cat $tmpfile`
  do
  file=`basename $i`
  
  echo "`date +'%Y/%m/%d %H:%M:%S'` BASH SCRIPT: Uploading file "$file"..." 
  scp $i $r_login@$r_host:"/"$r_folder
done
